home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Communications Toolbox / CTB Sample Code 1.0b16 / CTB Sources / Sources 2 / Terminal Tool for CTB / tset.p < prev    next >
Encoding:
Text File  |  1989-09-21  |  6.6 KB  |  305 lines  |  [TEXT/MPS ]

  1. { *** =================================================== ***
  2.  
  3.     Purpose:        Terminal tool's main setup procedures
  4.         for the choose dialog.  Manipulates the xbnd.r
  5.         dialog item list being "chosen."
  6.  
  7.     Module :        tset.p
  8.  
  9.     Authors:        Craig Hotchkiss, Alex Kazim, Byron Han, 
  10.                         Carol Lee
  11.                     Apple Computer, Inc.
  12.                     Networks & Communications
  13.                     20525 Mariani Drive
  14.                     Cupertino, CA 95014
  15.  
  16.     Version :        1.0d1
  17.  
  18.     Date :            9.may.89
  19.  
  20.     History :
  21.         9.may.89    Creation date
  22.  
  23.  
  24.     ©1989 Apple Computer, Inc.  All Rights Reserved.
  25.     This software is proprietary to Apple Computer, Inc.
  26.     It may not be copied, in whole or in part,
  27.     without the written consent of Apple Computer, Inc.
  28.  
  29.   *** =================================================== *** }
  30.     
  31.  
  32.  
  33.  
  34. UNIT TERMINALtset;
  35.  
  36. INTERFACE
  37.  
  38. USES     MemTypes,
  39.         QuickDraw,
  40.         OSIntf,
  41.         ToolIntf,
  42.         PasLibIntf,
  43.         Lists,
  44.         CRMSerialIntf,
  45.         CRMIntf,
  46.         CTBUtils,
  47.         CMIntf,
  48.         TMIntf,
  49.         FTIntf,
  50.         TerminalTool,
  51.         TermGlobalUnit;
  52.  
  53.  
  54.  
  55. FUNCTION tsetMAIN(pSetup: TMSetupPtr; message: Integer;
  56.     p1, p2: LongInt; VAR p3: LocalPtr): LongInt;
  57.  
  58.  
  59. IMPLEMENTATION
  60.  
  61.  
  62.  
  63. FUNCTION TMToolPreflight(pSetup: TMSetupPtr; 
  64.     pLocal: LocalPtr): LongInt;        FORWARD;
  65. PROCEDURE TMToolSetup(pSetup: TMSetupPtr; pLocal: LocalPtr);
  66.                     FORWARD;
  67. PROCEDURE TMToolItem(pSetup: TMSetupPtr; pInteger: IntegerPtr;
  68.     pLocal: LocalPtr);
  69.                     FORWARD;
  70. FUNCTION TMToolFilter(pEvent: EventPtr; pInteger: IntegerPtr;
  71.     pSetup: TMSetupPtr; pLocal: LocalPtr): Boolean;
  72.                     FORWARD;
  73. PROCEDURE TMToolCleanup(pLocal: LocalPtr);
  74.                     FORWARD;
  75.  
  76.  
  77.  
  78.  
  79. FUNCTION tsetMAIN(pSetup: TMSetupPtr; message: Integer;
  80.     p1, p2: LongInt; VAR p3: LocalPtr): LongInt;
  81.  
  82. { Returns success or failed via result and points the toolbox
  83. box in the direction chosen by 'message'.  Message integer
  84. range and the pSetup parameter are defined in TerminalTool.p 
  85. unit.  pSetup param used by the toolbox for messaging with
  86. the choose dialog. } 
  87.  
  88. VAR
  89.     theEvent: EventRecord;
  90.     theItem: Integer;
  91. BEGIN
  92.     tsetMAIN := 0;
  93.     CASE message OF
  94.         TMSpreflightMsg:
  95.                 tsetMAIN := TMToolPreflight(pSetup, p3);
  96.         TMSsetupMsg:
  97.                 TMToolSetup(pSetup, p3);
  98.         TMSitemMsg:
  99.             BEGIN
  100.                 TMToolItem(pSetup, IntegerPtr(p1), p3);
  101.             END;
  102.         TMSfilterMsg:
  103.                 IF TMToolFilter(EventPtr(p1), IntegerPtr(p2), 
  104.                     pSetup, p3) THEN
  105.                         tsetMAIN := 1;
  106.         TMScleanupMsg:
  107.             TMToolCleanup(p3);
  108.     END; { CASE }
  109. END;
  110.  
  111.  
  112. FUNCTION
  113.     TMToolPreflight(pSetup: TMSetupPtr; pLocal: LocalPtr): LongInt;
  114. VAR
  115.     theID: Integer;
  116.     theHandle: Handle;
  117. BEGIN
  118.  
  119.     { CommResource Manager used here to obtain a 'real' resource
  120.     ID of our current tool.  The result then uses DetachResource
  121.     to free the previously used tool. }
  122.     
  123.     theID := CRMLocalToRealID(ClassTM, pSetup^.procID, 'DITL', 1);
  124.     IF (theID = -1) THEN
  125.         BEGIN
  126.             TMToolPreflight := 0;
  127.             Exit(TMToolPreflight);
  128.         END;
  129.     theHandle := GetResource('DITL', theID);
  130.     IF (theHandle <> NIL) THEN
  131.         DetachResource(theHandle);
  132.     TMToolPreflight := LongInt(theHandle);
  133. END;
  134.  
  135.  
  136.  
  137.  
  138. PROCEDURE TMToolSetup(pSetup: TMSetupPtr; pLocal: LocalPtr);
  139. VAR
  140.     itemType: Integer;
  141.     itemHandle: Handle;
  142.     itemRect: Rect;
  143.     
  144.     pDialog: DialogPtr;
  145.     pConfig: TerminalPtr;
  146.     theCurrentSetting: Integer;
  147.     theOffset: Integer;
  148.     theItem: Integer;
  149. BEGIN
  150.     WITH pSetup^ DO
  151.     BEGIN
  152.         pConfig := TerminalPtr(theConfig);
  153.         theOffset := count - 1;
  154.         pDialog := theDialog;
  155.     END;
  156.     
  157.     WITH pConfig^ DO
  158.         BEGIN
  159.         
  160.         { Since my dialog controls are simple check boxes, 
  161.         their value is set accordingly.  } 
  162.         
  163.             GetDItem(pDialog, (theOffset + onlineBooleanItem), 
  164.                 itemType, itemHandle, itemRect);
  165.                 
  166.             { Here onlineBoolean refers to the field of my
  167.             private data structure.  The dialog controls are set
  168.             accordingly.  Other 2 controls set similarly. }
  169.             
  170.             IF onlineBoolean THEN
  171.                 SetCtlValue(ControlHandle(itemHandle), 1)
  172.             ELSE
  173.                 SetCtlValue(ControlHandle(itemHandle), 0);
  174.  
  175.  
  176.             GetDItem(pDialog, (theOffset + screenWidthItem), 
  177.                 itemType, itemHandle, itemRect);
  178.             IF screenWidth THEN
  179.                 SetCtlValue(ControlHandle(itemHandle), 1)
  180.             ELSE
  181.                 SetCtlValue(ControlHandle(itemHandle), 0);
  182.         
  183.  
  184.             GetDItem(pDialog, (theOffset + cursorStyleItem), 
  185.                 itemType, itemHandle, itemRect);
  186.             IF cursorStyle THEN
  187.                 SetCtlValue(ControlHandle(itemHandle), 1)
  188.             ELSE
  189.                 SetCtlValue(ControlHandle(itemHandle), 0);
  190.  
  191.  
  192.         END; { pConfig^ WITH }
  193. END;
  194.  
  195.  
  196.  
  197. PROCEDURE TMToolItem(pSetup: TMSetupPtr; pInteger: IntegerPtr;
  198.     pLocal: LocalPtr);
  199.  
  200. { This procedure handles users actions with the dialog item
  201. controls.  It even sets my private data structure like a good
  202. procedure should. } 
  203.  
  204. VAR
  205.     itemNumber: Integer;
  206.     itemType: Integer;
  207.     itemHandle: Handle;
  208.     itemRect: Rect;
  209.     
  210.     pDialog: DialogPtr;
  211.     pConfig: TerminalPtr;
  212.     
  213.     theOffset: Integer;
  214.     theItem: Integer;
  215.     theValue: Integer;
  216. BEGIN
  217.     WITH pSetup^, pLocal^ DO
  218.     BEGIN
  219.         pConfig := TerminalPtr(theConfig);
  220.         theOffset := count - 1;
  221.         theItem := pInteger^;
  222.         GetDItem(theDialog, theItem, itemType, itemHandle, itemRect);
  223.         theItem := pInteger^ - theOffset;            { local id    }
  224.       CASE theItem OF
  225.       
  226.       { Each case instance below, I simply toggle the item 
  227.           values. }
  228.         
  229.         onlineBooleanItem:
  230.             BEGIN
  231.                 theValue := GetCtlValue(ControlHandle(itemHandle));
  232.                 IF theValue = 1 THEN
  233.                     BEGIN
  234.                         SetCtlValue(ControlHandle(itemHandle), 0);
  235.                         pConfig^.onlineBoolean := false;
  236.                     END
  237.                 ELSE
  238.                     BEGIN
  239.                         SetCtlValue(ControlHandle(itemHandle), 1);
  240.                         pConfig^.onlineBoolean := true;
  241.                     END;
  242.                 ShowDItem (theDialog, (theOffset + onlineBooleanItem));
  243.             END;
  244.  
  245.         screenWidthItem:
  246.             BEGIN
  247.                 theValue := GetCtlValue(ControlHandle(itemHandle));
  248.                 IF theValue = 1 THEN
  249.                     BEGIN
  250.                         SetCtlValue(ControlHandle(itemHandle), 0);
  251.                         pConfig^.screenWidth := false;
  252.                     END
  253.                 ELSE
  254.                     BEGIN
  255.                         SetCtlValue(ControlHandle(itemHandle), 1);
  256.                         pConfig^.screenWidth := true;
  257.                     END;
  258.                 ShowDItem (theDialog, (theOffset + screenWidthItem));
  259.             END;
  260.  
  261.         cursorStyleItem:
  262.             BEGIN
  263.                 theValue := GetCtlValue(ControlHandle(itemHandle));
  264.                 IF theValue = 1 THEN
  265.                     BEGIN
  266.                         SetCtlValue(ControlHandle(itemHandle), 0);
  267.                         pConfig^.cursorStyle := false;
  268.                     END
  269.                 ELSE
  270.                     BEGIN
  271.                         SetCtlValue(ControlHandle(itemHandle), 1);
  272.                         pConfig^.cursorStyle := true;
  273.                     END;
  274.                 ShowDItem (theDialog, (theOffset + cursorStyleItem));
  275.             END;
  276.  
  277.       END; { CASE }
  278.     END; { WITH }
  279. END;
  280.  
  281.  
  282.  
  283. FUNCTION TMToolFilter(pEvent: EventPtr; pInteger: IntegerPtr;
  284.     pSetup: TMSetupPtr; pLocal: LocalPtr): Boolean;
  285.  
  286. { This function should be used to filter user's actions and 
  287. values.  My check boxes are so simple, I always return false. }
  288.  
  289. BEGIN
  290.     TMToolFilter := false;
  291. END;
  292.  
  293.  
  294.  
  295. PROCEDURE TMToolCleanup(pLocal: LocalPtr);
  296.  
  297. { If I was allocating any special structures or had values
  298. that needed to reset, they would have been accomplished here. }
  299. BEGIN
  300.     { nothing for now }
  301. END;
  302.  
  303.  
  304. END.
  305.